#include "CPlayerMgr.h"

using namespace su;
using namespace std;
using namespace proto;

CPlayerMgr& gPlayerMgr = CPlayerMgr::Ins();

CPlayer* CPlayerMgr::Find(const string& channelId)
{
	auto it = m_channelId2player.find(channelId);
	L_COND(it != m_channelId2player.end(), nullptr);
	return it->second.get();
}

CPlayer* CPlayerMgr::CreatePlayer(const string& channelId)
{
	auto it = m_channelId2player.find(channelId);
	L_COND(it == m_channelId2player.end(), nullptr);
	auto player= make_unique< CPlayer>();
	CPlayer* p = player.get();
	p->m_Base.channelId = channelId;
	p->m_Base.name = channelId;
	m_channelId2player.emplace(channelId, std::move(player));
	return p;
}



void CPlayerMgr::DelPlayer(const string& channelId, bool isSave)
{
	auto& m_id2player = CPlayerMgr::Ins().m_channelId2player;
	auto it = m_id2player.find(channelId);
	L_COND_V(it != m_id2player.end());
	LDEBUG("del player ", it->second->Id());
	m_id2player.erase(it);
}


void CPlayerMgr::OnFiveMinute()
{
	for (auto& i : m_channelId2player)
	{
	}
}
